package com.qezhhnjy.bilibili.controller;

import com.qezhhnjy.bilibili.entity.CommonResult;
import com.qezhhnjy.bilibili.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author zhaoyangfu - 2021/4/3 15:56
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    // 单机模式
    public static final String PAYMENT_URL = "http://localhost:8001";
    // 集群模式
    public static final String PAYMENT_URL_CLUSTER = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL_CLUSTER + "/payment/create", payment, CommonResult.class);
    }

    @GetMapping("/payment/zipkin")
    public String zipkin() {
        return restTemplate.getForObject(PAYMENT_URL_CLUSTER + "/payment/zipkin", String.class);
    }
}
